package utilz;

import mian.Game;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class HelpMethods {
    private static boolean IsSolid(float x,float y,int[][]lvlData){
        if (x<0||x>= Game.GAME_WIDTH)
            return true;
        if (y<0||y>=Game.GAME_HEIGHT)
            return true;
        float xIndex=x/Game.TILE_SIZE;
        float yIndex=y/Game.TILE_SIZE;
        int value=lvlData[(int) yIndex][(int) xIndex];

        if (value>=48||value<0||value!=11)
            return true;
        return false;
    }
    public static boolean CanMoveHere(float x,float y,float width,float height,int[][]lvlData){
       if (!IsSolid(x,y,lvlData))
           if (!IsSolid(x+width,y+height,lvlData))
               if (!IsSolid(x+width,y,lvlData))
                   if (!IsSolid(x,y+height,lvlData))
                       return true;
                   return false;
    }
    public static float GetEntityXposNextTOWall(Rectangle2D.Float hitBox,float xSpeed){
        int currentTile=(int) (hitBox.x/Game.TILE_SIZE);
        if (xSpeed>0){
            int tileXPos=currentTile*Game.TILE_SIZE;
            int xOffset=(int) (Game.TILE_SIZE-hitBox.width);
            return  tileXPos+xOffset-1;
        }else {
            return currentTile*Game.TILE_SIZE;
        }
    }
    public static float GetEntityYposNextTOWall(Rectangle2D.Float hitBox,float airSpeed){
        int currentTile=(int) (hitBox.y/Game.TILE_SIZE);
        if (airSpeed>0){
            int tileYPos=currentTile*Game.TILE_SIZE;
            int yOffset=(int) (Game.TILE_SIZE-hitBox.height);
            return  tileYPos+yOffset-1;
        }else {
            return currentTile*Game.TILE_SIZE;
        }}
        public static boolean IsEntityOnFloor(Rectangle2D.Float hitBox,int[][] lvlData){
        if (!IsSolid(hitBox.x, hitBox.y+ hitBox.height+1,lvlData ))
            if (!IsSolid(hitBox.x+ hitBox.width, hitBox.y+ hitBox.height+1,lvlData ))
                return false;
            return true;
        }
}